const { ipcMain } = require('electron');
const topEmitter = require('./topinfo');

const initTopEmitter = () => {
    topEmitter.start({
        pid_limit: 100,
        pid_sort: (a,b) => {
            return a.mem - b.mem;
        },
        pid_filter: (proc) => {
            return proc;
        },
    });
}
module.exports = function(win) {
    initTopEmitter();
    // 
    topEmitter.on('data', data => {
        win.webContents.send('onCpuInfo', JSON.stringify(data));
    });
    // 打开控制台
    ipcMain.on('openDevTools', () => {
        win.webContents.openDevTools(); 
    });
}
module.exports.closeTop = () => {
    topEmitter.stop();
}